<script>
import { getClassifyTree } from '@/api/material/classify'
export default {
  name: 'MaterialClassify',
  props: {
    value: Array,
    disabled: { type: Boolean, default: false },
    props: { type: Object, default: () => ({ label: 'title' }) },
    on: { type: Object, default: null }
  },
  data: () => ({ options: [] }),
  created() {
    this.init()
  },
  methods: {
    async init() {
      try {
        const { data } = await getClassifyTree()
        this.options = data.data
      } catch (error) {
        console.log(error)
      }
    },
  },
  render(h) {
    return h('el-cascader', {
      ref: 'editCascader',
      props: {
        ...this.$props,
        clearable: true,
        value: this.value,
        props: this.props,
        options: this.options
      },
      attrs: { placeholder: '请选择物料分类' },
      on: this.on || {
        ...this.$listeners,
        input: value => this.$emit('input', value),
        change: () => { let nodeContent = this.$refs['editCascader'].getCheckedNodes()
        this.$emit('change',nodeContent[0].pathLabels.join('/'))}
      }
    })
  }
}
</script>
